﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lidgren.Network;
using Lidgren.Network.Xna;

namespace SharedLib.Network.Client
{
    public class ClientSender
    {
        ClientProperties Pbag;
        NetClient Client;
        NetOutgoingMessage outmsg;

        public ClientSender(NetClient netc, ClientProperties pb)
        {
            Client = netc;
            Pbag = pb;
        }

        public void SendJoinGame(string ip)
        {
            outmsg = Client.CreateMessage();
            outmsg.Write(Constants.CLIENT_VERSION);
            outmsg.Write(Pbag.Player.Name);
            Client.Connect(ip, Constants.REMOTE_PORT, outmsg);

        }

        public void SendPlayerInWorld()
        {
            outmsg = Client.CreateMessage();
            outmsg.Write((byte)SharedLib.Constants.PacketType.PlayerInWorld);
            outmsg.Write(true);
            Client.SendMessage(outmsg, NetDeliveryMethod.ReliableOrdered);
        }

        public void SendMovementUpdate()
        {
            outmsg = Client.CreateMessage();
            outmsg.Write((byte)SharedLib.Constants.PacketType.EntityMovementUpdate);
            outmsg.Write(Pbag.Player.Position);
            Client.SendMessage(outmsg, NetDeliveryMethod.ReliableOrdered);
        }

        public void SendRotationUpdate()
        {
            outmsg = Client.CreateMessage();
            outmsg.Write((byte)SharedLib.Constants.PacketType.EntityRotationUpdate);
            outmsg.Write(Pbag.Player.Rotation);
            Client.SendMessage(outmsg, NetDeliveryMethod.ReliableOrdered);
        }

    }
}
